# 分阶段构建
## 编译阶段
FROM node:22.15.0-alpine3.21 AS build

WORKDIR /app

### 复制依赖文件
COPY .yarn .yarn/
COPY .yarnrc.yml yarn.lock package.json ./
COPY browser/package.json ./browser/
COPY core/package.json ./core/
COPY server/package.json ./server/

### 安装依赖
RUN yarn install --immutable

### 复制项目代码
COPY . .

### 编译
RUN yarn --cwd ./browser build
RUN yarn --cwd ./server build
RUN yarn --cwd ./core build

RUN cp -r ./browser/dist ./dist
RUN rm -rf ./browser

## 最终阶段
FROM node:22.15.0-alpine3.21

WORKDIR /app

COPY --from=build /app /app


ENV PORT=5125

EXPOSE ${PORT}

ENTRYPOINT ["yarn", "--cwd", "./server", "dev"]
#ENTRYPOINT tail -f /dev/null

# docker build -t firfe/connect_four:2025.06.29 .
